<template>
  <!--会签管理-我的审批-付款计划详情弹窗-表单-->
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="disabled" class="scroll-view" style="height: 400px">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="模板名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billsTemplateName">
              <a-input :disabled="disabled" v-model="model.billsTemplateName" style="color: black;" placeholder="请输入标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单据类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billsType">
              <j-dict-select-tag placeholder="请选择单据类型" v-model="model.billsType"
                dictCode="bills_type"></j-dict-select-tag>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="单据模板" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiptsModel">
              <j-dict-select-tag placeholder="请选择单据类型" v-model="model.receiptsModel"
                dictCode="receipts_model"></j-dict-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否需要部门领导审核" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="isLeadership">
              <a-radio-group :disabled="disabled" :options="isLeaderships" :default-value="model.isLeadership"
                @change="onChange('isLeadership',$event)"/>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
              <a-select :options="levelOneOptions" placeholder="请选择项目" v-model="model.projectId">
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="审批层级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approveHierarchy">
              <a-input :disabled="disabled" v-model="model.approveHierarchy" style="color: black;" placeholder="请输入审批层级"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>
<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'WtBrandForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: true,
      required: false,
    },
    pageType:{
      type:String,
      default:''
    }
  },
  data() {
    return {
      title: '撤销原因',
      model: {
        id:'',
        status:'',
        projectId:'',
        billsTemplateName:'',
        approveHierarchy:'',
        isLeadership:'0',
        receiptsModel:'',
      },
      visible1: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 10 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 14 },
      },
      model1: {
        feedback: '',
        id: '',
        status: '',
      },
      confirmLoading: false,
      validatorRules: {},
      levelOneOptions: [],
      // levelTwoOptions: [],
      // levelThreeOptions: [],
      treeData: [],
      // fileList: [],
      treeData1: [],
      treeData3: [],
      id: '',
      ids: [],
      status: '',
      idss: '', //提交id
      url: {
        add: '/countersign/wtCountersignTemplate/add',
        edit: '/countersign/wtCountersignTemplate/edit',
        queryById: '/wtBrand/queryById',
      },
      isLeaderships: [{
        label: '否',
        value: '0'
      }, {
        label: '是',
        value: '1'
      }], //是否漏油/气/水
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    //this.modelDefault = JSON.parse(JSON.stringify(this.model))
    getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
      if (res.success) {
        this.treeData = []
        let treeList = res.result
        for (let a = 0; a < treeList.length; a++) {
          let temp = treeList[a]
          temp.isLeaf = temp.leaf
          this.treeData.push(temp)
        }

        this.levelOneOptions = [...this.treeData].map((v) => {
          return {
            ...v,
            value: v.id,
            label: v.departName,
          }
        })
      }
    })
  },
  methods: {
    init(){
      this.model = {
        id:'',
        status:'',
        projectId:'',
        billsTemplateName:'',
        approveHierarchy:'',
        isLeadership:'0',
        receiptsModel:'',
      };
    },
    onChange(type, item, ) {
      console.log(1, type, item);
      if (type === 'isLeadership') {
        this.model.isLeadership = item.target.value;
      }
    },
    confirmPrivacy() {
      // console.log('同意了用户协议')
      // console.log(this.privacyDialogShow)l
      this.visible1 = false
      // console.log(this.privacyDialogShow)
    },
    cancelPrivacy() {
      // console.log('拒绝了用户协议')
      this.visible1 = false
    },
    edit(record) {
      console.log(11,record)
      this.model = Object.assign({}, record)
      this.visible = true
      this.loadTree(record)
      this.id = record.id
      this.status = record.status
      // console.log('few',record);
    },
    loadTree(record) {
      var that = this
      getAction(`/wtCountersign/countersignMaterialStatement/queryByCountersignId?countersignId=${record.id}`).then(
        (res) => {
          if (res.success) {
            that.treeData1 = res.result
            // console.log('erferw',that.treeData1);
            this.model = that.treeData1
            this.treeData3 = res.result.list
            this.list = res.result.list
            this.ids = this.list.find((obj) => obj.status == '1')
            // console.log('dwaq1', this.ids);
            this.idss = this.ids.id
            // for (let a = 0; a < treeList1.length; a++) {
            //   // console.log('ewq2');
            //   let temp = treeList1[a]
            //   temp.isLeaf = temp.leaf
            //   that.treeData1.push(temp)
            // console.log('dwaq1',that.treeData1);
          }
        }
      )
    },
    add() {
      this.edit(this.modelDefault)
    },

    chexiao() {
      this.visible1 = true
    },
    bohui() {
      const that = this
      // 触发表单验证
      that.model1.id = that.idss
      that.model1.status = '3'
      // console.log('432', that.model1)
      // debugger
      if (!that.model1.feedback) {
        alert('审批意见不能为空,请填写')
      }else{
        httpAction('/countersign/wtCountersignProcess/submitExamineApprove', this.model1, 'POST')
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message)
            that.$emit('ok')
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
      }
    },
    submitForm() {
      const _self = this
      let params = {};
      let httpurl = ''
      if (this.pageType === 'add') {
        httpurl = this.url.add;
        params = this.model;
      } else if (this.pageType === 'edit') {
        httpurl = this.url.edit;
        params = this.model;
      }
      // 触发表单验证
      this.confirmLoading = true;
      console.log('提交表单', params)
      // debugger
      httpAction(httpurl, params, 'POST').then((res) => {
          if (res.success) {
            _self.$message.success(res.message);
            _self.init();
            _self.$emit('ok')
          } else {
            _self.$message.warning(res.message)
          }
        })
        .finally(() => {
          _self.confirmLoading = false
        })
    },
  },
}
</script>
  <style scoped>
.scroll-view {
  overflow: auto;
  overflow-y: scroll;
}
</style>